package module.service.impl;

import common.bean.SearchPageResult;
import common.bean.SearchParameter;
import module.dao.AssessmentStandardValueDao;
import module.model.AssessmentStandardValueModel;
import module.service.AssessmentStandardValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 资料标准值
 */
@Service
public class AssessmentStandardValueServiceImpl implements AssessmentStandardValueService {
    @Autowired
    private AssessmentStandardValueDao assessmentStandardValueDao;

    @Transactional
    public AssessmentStandardValueModel saveAssessmentStandardValue(AssessmentStandardValueModel assessmentStandardValueModel) {
        if(assessmentStandardValueModel.getStandardValueId()!=null){
            return assessmentStandardValueDao.update(assessmentStandardValueModel);
        }else {
            assessmentStandardValueModel.setCreateDate(new Date());
            assessmentStandardValueDao.save(assessmentStandardValueModel);
        }
        return assessmentStandardValueModel;
    }

    @Transactional
    public List<AssessmentStandardValueModel> getAssessmentStandardValueModelListBySearchParameter(SearchParameter searchParameter) {
        return assessmentStandardValueDao.getAssessmentStandardValueModelListBySearchParameter(searchParameter);
    }

    @Transactional
    public List<AssessmentStandardValueModel> getAssessmentStandardValueByDataId(Long dataId) {
        SearchParameter searchParameter = new SearchParameter();
        searchParameter.addParam("dataId",dataId);
        return getAssessmentStandardValueModelListBySearchParameter(searchParameter);
    }
    @Transactional
    public void deleteAssessmentStandardValueModelById(Long standardValueId) {
        assessmentStandardValueDao.deleteById(AssessmentStandardValueModel.class,standardValueId);
    }
    @Transactional
    public SearchPageResult<AssessmentStandardValueModel> getAssessmentStandardValueModelListPage(SearchParameter searchParameter) {
        return assessmentStandardValueDao.getAssessmentStandardValueModelListPage(searchParameter);
    }
    @Transactional
    public AssessmentStandardValueModel getAssessmentStandardValueModelByValueId(Long valueId) {
        return assessmentStandardValueDao.load(AssessmentStandardValueModel.class,valueId);
    }
}
